package com.mybatis.springboot_mybatis01.mapper;

import com.mybatis.springboot_mybatis01.UserSexEnum;
import com.mybatis.springboot_mybatis01.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

//@Mapper
public interface UserMapper {

    /**
     * 查询所有用户
     * @return
     */
    @Select("select * from user")
    @Results({
        @Result(property = "userName", column = "user_name"),
        @Result(property = "passWord", column = "pass_word"),
//        @Result(property = "userSex", column = "user_sex",javaType = UserSexEnum.class),
        @Result(property = "id", column = "id"),
        @Result(property = "detail", column = "detail"),
    })
    List<User> findAll();


    /**
     * 根据id查询用户
     * @param id
     * @return
     */

    @Select("select * from user where id=#{id}")
    @Results({
            @Result(property = "userName", column = "user_name"),
            @Result(property = "passWord", column = "pass_word"),
            @Result(property = "userAddress", column = "userAddress"),
            @Result(property = "userSex", column = "user_sex",javaType = UserSexEnum.class),
            @Result(property = "id", column = "id"),
            @Result(property = "detail", column = "detail"),
    })
    User getOne(Integer id);


    /**
     * 添加用户
     * @param user
     */
    @Insert("insert into user(user_name,user_sex,user_address,pass_word,detail) " +
            "VALUES(#{userName},#{userSex},#{userAddress},#{passWord},#{detail})")
    void insetUser(User user);


    /**
     * 更新用户
     * @param user
     */
    @Update("update user set user_name=#{userName},user_sex=#{userSex},user_address=#{userAddress}" +
            ",pass_word=#{passWord},detail=#{detail} where id=#{id}")
    void updateUser(User user);


    /**
     * 根据id删除用户
     * @param id
     */
    @Delete("delete from user where id=#{id}")
    void deleteUser(Integer id);

}
